package com.bdd.aspect;


import com.bdd.Result.Result;
import com.bdd.Result.ResultCode;
import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description 全局异常处理
 * @author huanghaining
 * @date 2022/3/18
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalArgumentException.class)
    public Result IllegalArgumentException(IllegalArgumentException e){
        return new Result(ResultCode.BAD_REQUEST_INVALID_PARAMETER,e.getMessage());
    }


    @ExceptionHandler(AccountException.class)
    public Result IllegalAccountException(AccountException e){
        return new Result(ResultCode.UNAUTHORIZED,"请先登录");
    }


    @ExceptionHandler(IncorrectCredentialsException.class)
    public Result IncorrectCredentialsException(IncorrectCredentialsException e){
        return new Result(ResultCode.UNAUTHORIZED,"用户名或密码错误或为空！");
    }

    @ExceptionHandler(AuthorizationException.class)
    public Result IncorrectAuthorizationException(AuthorizationException e){
        return new Result(ResultCode.UNAUTHORIZED,"没有权限！");
    }

}
